
package com.huaweicloud.saaslanding.install.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huaweicloud.saaslanding.basic.utils.EncryptionUtil;
import com.huaweicloud.saaslanding.dao.common.entity.security.WorkSecretKey;
import com.huaweicloud.saaslanding.install.properties.DatabaseConfig;
import com.huaweicloud.saaslanding.install.repository.WorkSecretKeyMapper;

import jakarta.annotation.Resource;

import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @since 2022-07-28
 */
@Component
public class SaltUtil {
    @Resource
    private WorkSecretKeyMapper workSecretKeyMapper;

    @Resource
    private DatabaseConfig databaseConfig;

    /**
     * 获取jasypt配置加密盐
     *
     * @return jasypt配置加密盐
     */
    public String findJasypt() {
        QueryWrapper<WorkSecretKey> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_del", 0).eq("tenant_code", databaseConfig.getConnectionInfo().getDbName());
        WorkSecretKey workSecretKey = workSecretKeyMapper.selectOne(queryWrapper);
        return EncryptionUtil.decrypt(workSecretKey.getPwdSalt(), workSecretKey.getPassword());
    }

}
